<?php
namespace app\backend\org;

use \app\backend\model\Menu;

class Helper
{
    static  public function pid($type)
    {
        $data = Menu::all();
        foreach ($data as $k=>$v){
            if( $v["menu_name_cn"] == $type){
                $pid = $v["menu_id"];
                break;
            }
        }
        $org =   Recursion::_child_id($data,$pid);
        $org[]=$pid;
        return $org;
    }

    static public function crumbs($id,$language)
    {
        $data = Menu::all();
        //var_dump($data);exit;
        $p_id= [];
        foreach ($data as $k=>$v){
            if($v["menu_id"]==$id && $p_id !=0){
                $p_id = array_merge($p_id,self::crumbs($v["p_id"],$language));
                if($language=="cn"){
                    $p_id[]=array("id"=>$id,"p_id"=>$v["p_id"],"name_cn"=>$v["menu_name_cn"]);
                }elseif ($language=="en"){
                    $p_id[]=array("id"=>$id,"p_id"=>$v["p_id"],"name_en"=>$v["menu_name_en"]);
                }
            }
        }
        return $p_id;
    }


    static public function getChildrenIds($data){

    }
}